package com.javabi.htmlbuilder.css;

import java.util.ArrayList;
import java.util.List;

/**
 * A CSS Style
 */
public class CSSStyle implements CSSElement {

	/** The selector list. */
	private List<CSSSelector> selectorList = new ArrayList<CSSSelector>();
	/** The declaration set. */
	private CSSDeclarationSet declarationSet = new CSSDeclarationSet();

	/**
	 * Returns the declaration set.
	 * @return the declaration set.
	 */
	public CSSDeclarationSet declarations() {
		// ESCA-JAVA0259: allow return of raw set, not thread safe
		return declarationSet;
	}

	/**
	 * Add the given selector.
	 * @param selector the selector.
	 * @return this style.
	 */
	public CSSStyle addSelector(CSSSelector selector) {
		if (selector == null) {
			throw new NullPointerException();
		}
		selectorList.add(selector);
		return this;
	}

	/**
	 * Append this to the given css builder.
	 * @param css the css builder.
	 * @return the css builder.
	 */
	public CSSBuilder appendTo(CSSBuilder css) {
		css.newLine();
		css.selectors(selectorList);
		css.declarations(declarationSet, true);
		return css;
	}

}
